/* 
 * Copyright [2018] [Alex/libo(liboware@gmail.com)]
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.apidoc.swagger.yaml;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.hyts.apidoc.swagger.bean.PathBean;
import com.hyts.apidoc.swagger.bean.TagBean;
import com.hyts.template.freemarker.FreemarkerContext;
import com.hyts.template.freemarker.FreemarkerStream;
import io.swagger.annotations.Api;

import java.util.List;
import java.util.Map;

/**
 * @author LiBo/Alex
 * @since TODO引入特定改变发布版本
 * @version V1.0 
 */
@Api(value="adasda")
public class YamlDataHandler {

    /**
     * @fieldName printer
     * @fieldType FreemarkerStream<Map<String,Object>>
     */
    static FreemarkerStream<Map<String,Object>> printer = null;

    static final String BASE_TEMPLATE_FILE_PATH = "/swagger/";

    static final String SWAGGER_FILE_TEMPLATE_NAME = "swagger-template.ftl";


    /**
     * 构造器
     */
    public YamlDataHandler() {
        printer = new FreemarkerStream<Map<String,Object>>(new FreemarkerContext()
                .createContext(YamlDataHandler.class,BASE_TEMPLATE_FILE_PATH));
    }

    /**
     * 输出操作
     * @param param
     * @return
     */
    public void writer(Map<String,Object> param,String filePath){
        printer.writer(SWAGGER_FILE_TEMPLATE_NAME,param,filePath);
    }

    /**
     * 操作服务
     * @param args
     */
    public static void main(String[] args){
        Map<String,Object> param = Maps.newHashMap();
        param.put("description","线下渠道管理系统");
        param.put("version","V1.0.0");
        param.put("title","收费电子化API文档");
        param.put("email","liboware@hotmail.com");
        param.put("licenseName","Apache 2.0");
        param.put("licenseUrl","http://www.apache.org/licenses/LICENSE-2.0.html");
        param.put("host","enzhico.com");
        param.put("basePath","/api/v1");
        List<TagBean> tags = Lists.newArrayList();
        tags.add(new TagBean("商铺","商铺相关操作"));
        tags.add(new TagBean("用户","用户相关的操作"));
        List<String> schemes = Lists.newArrayList();
        schemes.add("https");
        param.put("schemes",schemes);
        param.put("tags",tags);
        List<PathBean> pathBeanList = Lists.newArrayList();
        PathBean pathBean = new PathBean();
        pathBean.setMethod("get");
        pathBean.setPath("/getUser");
        pathBean.setDescription("获取用户列表，有多少返回多少，没有分页");
        List<String> prduce = Lists.newArrayList();
        prduce.add("application/json");
        pathBean.setSummary("获取用户列表");
        pathBean.setProduces(prduce);
        pathBean.setOperationId("listUsers");
        pathBean.setProduces(prduce);
        pathBeanList.add(pathBean);
        param.put("produces",prduce);
        param.put("paths",pathBeanList);
        new YamlDataHandler().writer(param,"D:\\other_space\\coffice-toolbox\\coffice-toolbox-archive\\coffice-toolbox-apidoc\\src\\main\\resources\\swagger\\template-test.yaml");
       // new YamlDataHandler().writer(param,"D:\\codes\\code-alexlibo\\code-myself\\osfd\\coffice-toolbox\\coffice-toolbox-apidoc\\src\\main\\resources\\swagger\\swagger.yaml");
    }


}
